﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;

namespace SaveObjectToDatabase
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Diagnostics.Trace.WriteLine("$$$$$$$$" + ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString);

            ObjectToSave obj = new ObjectToSave(){CardNo = 1234,Name= "ObjectSavingTest"};
            DataTable dt = new DataTable();
            dt.Columns.Add("PropertyPath",typeof(string));
            dt.Columns.Add("PropertyName", typeof(string));
            dt.Columns.Add("PropertyValue", typeof(object));
            dt.Columns.Add("PropertyType", typeof(string));
            dt.Columns.Add("PropertyOrder", typeof(int));
            dt.Columns.Add("Category", typeof(string));
            dt.AcceptChanges();
            obj.SaveProperties(dt,true);

            
            DumpDataTable(dt);
        }

        public static void DumpDataTable(DataTable dt)
        {
            List<string> columnNameList = new List<string>();
            foreach (DataColumn c in dt.Columns)
            {
                columnNameList.Add(c.ColumnName);
            }

            string[] nameListArray = columnNameList.ToArray();

            StringBuilder sb = new StringBuilder();

            foreach (DataRow dr in dt.Rows)
            {
                sb.Clear();
                foreach (string s in columnNameList)
                {
                    sb.Append(dr[s]).Append("\t");
                }
                Console.WriteLine(sb.ToString());
            }
        }
    }
}
